using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace 水库上位机
{
    public class PaaTextbox : UPanel
    {
        private Label[] parameterLabels;
        private string[] parameterValues;
        private string title = "参数信息";
        private Font titleFont = new Font("微软雅黑", 9F, FontStyle.Bold);
        private Font contentFont = new Font("微软雅黑", 8F);
        private string varName = string.Empty;

        [Category("外观")]
        [Description("标题文本")]
        public string Title
        {
            get { return title; }
            set 
            {
                title = value;
                this.Invalidate();
            }
        }

        [Category("数据")]
        [Description("关联的ModBus变量名")]
        public string VarName
        {
            get { return varName; }
            set { varName = value; }
        }

        public PaaTextbox()
        {
            this.BackColor = Color.White;
            this.CornerRadius = 8;
            this.BorderColor = Color.DarkBlue;
            this.BorderWidth = 2;
        }

        public void SetParameters(params string[] parameters)
        {
            parameterValues = parameters;
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            // 绘制标题
            using (Brush brush = new SolidBrush(Color.DarkBlue))
            {
                g.DrawString(title, titleFont, brush, 10, 5);
            }

            // 绘制分隔线
            using (Pen pen = new Pen(Color.LightGray, 1))
            {
                g.DrawLine(pen, 5, 25, this.Width - 5, 25);
            }

            // 绘制参数信息
            if (parameterValues != null)
            {
                for (int i = 0; i < parameterValues.Length; i++)
                {
                    using (Brush brush = new SolidBrush(Color.Black))
                    {
                        g.DrawString(parameterValues[i], contentFont, brush, 10, 30 + i * 20);
                    }
                }
            }
        }
    }
}